﻿namespace PillBox.Client.Framework
{
    using System;

    public class DeActivateCurrentViewResult : IResult
    {
        public event EventHandler Completed;

        public void Execute()
        {
            var navigation = IoC.GetInstance<INavigation>();

            IView view = navigation.Content as IView;

            if (view != null)
            {
                view.DeActivate(RaiseCompletedEvent);
            }
            else
            {
                RaiseCompletedEvent();
            }
        }

        private void RaiseCompletedEvent()
        {
            var handler = this.Completed;

            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }
        }
    }
}